package rsb212.num23.ysh.d1130.chap06;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.SortedSet;

public class TreeSet {
     static List<Student> list=new ArrayList<>();;

    public static void main(String[] args) {
        //创建5个学生对象，存入TreeSet集合
        //比较大小的时候，在创建对象的时候直接给他比较器comparator<?super E>comparator
        java.util.TreeSet<Student> treeSet=new java.util.TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //按成绩比较
                //int ret=(int) (o1.getScore()-o2.getScore());
                int ret=(int)(o2.getScore()-o1.getScore());
                //按照学号进行比较
                //int ret =Integer.valueOf(o1.getNumber())-Integer.valueOf(o2.getNumber());

                return ret;
            }
        });
        treeSet.add(new Student("唐凯悦","41926081",90));
        treeSet.add(new Student("彭真","41926084",78));
        treeSet.add(new Student("阎佳","41926022",91));
        treeSet.add(new Student("汪龙","41926010",87));
        treeSet.add(new Student("李安典","419260385",97));
        System.out.println("最高分"+treeSet.first());//最高分
        System.out.println("最高分"+treeSet.last());//最低分

        //不及格
        SortedSet<Student> sortedSet= treeSet.headSet(new Student("aa","8899",98));
        for (Student student:sortedSet){
            System.out.println(student);
        }
        //平均分
        double avg=treeSet.stream().mapToDouble(a->a.getScore()).average().getAsDouble();
        System.out.println("平均分是"+avg);
        //60-80的学生的成绩
        List<Student> stus=Tools.getScore(list,80,90);
        System.out.println("80----90之间学生是"+stus);
        List<Student> stus2=Tools.getScore(list,70,80);
        System.out.println("70----80之间学生是"+stus2);




        //遍历
      /*  treeSet.forEach(s ->{
            System.out.println(s);
        } );*/

    }
}
